﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace GluePathModule
{
    [XmlInclude(typeof(GluePathItemLine))]
    public class GluePathItemPoint : GluePathItemBase
    {
        [Description("点设定"), Category("点设定")]
        public PointData Pos
        {
            get;
            set;
        }
        [Description("点设定"), Category("点设定")]
        public PointData PosTransfer
        {
            get;
            set;
        }
        [Description("点设定"), Category("点设定")]
        public double 出胶时间
        {
            get;
            set;
        }
        [Description("点设定"), Category("点设定")]
        public double 关胶延时
        {
            get;
            set;
        }

        [Browsable(false)]
        public bool bUseZheight
        {
            get;
            set;
        }
        [Browsable(false)]
        public string UseZheightName
        {
            get;
            set;
        }
        [Browsable(false)]
        public int iDrawStep
        {
            get;
            set;
        }
        public GluePathItemPoint()
        {
            iDrawStep = 0;
            Name = "";
            Remark = "";
            UseZheightName = "";
            Pos = new PointData();
        }

        public override void DrawItem(DrawerControl drawer, DrawMode drawMode = DrawMode.UnitIsSelected)
        {
            //base.DrawItem(drawer);
            if (drawMode == DrawMode.Background)
            {
                drawer.DrawPoint(new System.Drawing.Pen(System.Drawing.Color.Gray, 1), Pos.X, Pos.Y);
                return;
            }
            else if (drawMode == DrawMode.UnitIsNotSelect)
            {
                drawer.DrawPoint(new System.Drawing.Pen(System.Drawing.Color.White, 3), Pos.X, Pos.Y);
                return;
            }
            if (空动作路径)
            {
                drawer.DrawPoint(new System.Drawing.Pen(System.Drawing.Color.Blue, 3), Pos.X, Pos.Y);
            }
            else
            {
                drawer.DrawPoint(new System.Drawing.Pen(System.Drawing.Color.Green, 3), Pos.X, Pos.Y);
            }

            if (Select)
            {
                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 2);
                drawer.DrawPoint(pen, Pos.X, Pos.Y, 2);
            }
            

        }
       
        public override bool IsOnSelect(double dPosX, double dPosY, double dJudageDis)
        {
            


            if (dPosX > (Pos.X - dJudageDis) && dPosX < (Pos.X + dJudageDis) && dPosY > (Pos.Y - dJudageDis) && dPosY < (Pos.Y + dJudageDis))
            {
                if (Select == false)
                    Select = true;
                return Select;
            }
            else
            {
                //Select = false;
                return Select;
            }

        }
        /// <summary>
        /// 获取两点的距离
        /// 作者：陈   时间：20200810
        /// </summary>
        /// <returns></returns>



        ///
        ///点x1到线段x1-x2的距离
        /// 作者：陈   时间：20200810
        /// </summary>
        /// <returns></returns>


        public override bool GetLastPoint(out double dPosX, out double dPosY, out double dPosZ, out double dPosU)
        {
            dPosX = Pos.X;
            dPosY = Pos.Y;
            dPosZ = Pos.Z;
            dPosU = Pos.U;
            return true;
        }
        public override bool GetFirstPoint(out double dPosX, out double dPosY, out double dPosZ, out double dPosU)
        {
            dPosX = Pos.X;
            dPosY = Pos.Y;
            dPosZ = Pos.Z;
            dPosU = Pos.U;
            return true;
        }
        
        public override GluePathItemBase CopyItem()
        {
            GluePathItemPoint itemNew = (GluePathItemPoint)MemberwiseClone();
            itemNew.Pos = new PointData(Pos);
            itemNew.PosTransfer = new PointData(PosTransfer);
            return itemNew;
        }
        override public GluePathItemBase Paste()
        {

            return CopyItem();
        }
        public override void OffSetItem(double dOffSetX, double dOffSetY)
        {
            Pos.X = Pos.X + dOffSetX;
            Pos.Y = Pos.Y + dOffSetY;
        }
        override public void PathUnitMouseDown(double dMouseX, double dMouseY, double dScandle)
        {
            if (Select == false)
                return;
            if (iAdjustStep == 0)
            {
                if (dMouseX > (Pos.X - (5 / dScandle)) && dMouseX < (Pos.X + (5 / dScandle)) && dMouseY > (Pos.Y - (5 / dScandle)) && dMouseY < (Pos.Y + (5 / dScandle)))
                {
                    iAdjustStep = 1;
                }
                else
                {

                }

            }
        }
        override public void PathUnitMouseMove(double dMouseX, double dMouseY)
        {
            if (Select == false)
                return;
            if (iAdjustStep > 0)
            {
                Pos.X = dMouseX;
                Pos.Y = dMouseY;

            }
        }
        override public void PathUnitMouseUp(double dMouseX, double dMouseY)
        {
            if (Select == false)
                return;
            if (iAdjustStep == 1)
            {
                Pos.X = dMouseX;
                Pos.Y = dMouseY;
                iAdjustStep = 0;
                return;


            }
            if (iAdjustStep == 2)
            {
                Pos.X = dMouseX;
                Pos.Y = dMouseY;
                iAdjustStep = 0;
               
                return;
            }
            if (iAdjustStep == 3)
            {
                Pos.X = dMouseX;
                Pos.Y = dMouseY;
                iAdjustStep = 0;
              
            }
        }
        
        //public override void PushItemToCure(ContinuePathUnit pathUnitCurrent, int indexId)
        //{
        //    MainModule.TableRunner tableRunner = new MainModule.TableRunner(pathUnitCurrent.GlueTableName);
        //    //tableRunner.SetTool("Default");


        //    FiveZhouSetting fiveZhouSetting = null;
        //    if (ContinuePathManager.glueTableGlobalSettingCenter.dicGlueTableGlobalSettingUnit.ContainsKey(pathUnitCurrent.GlueTableGlobalDataName))
        //    {
        //        fiveZhouSetting = ContinuePathManager.glueTableGlobalSettingCenter.dicGlueTableGlobalSettingUnit[pathUnitCurrent.GlueTableGlobalDataName].FixAxisSetting;


        //    }
        //    else
        //    {
        //        return;
        //    }
        //    MainModule.TableMotionSpeed spdXYH = new MainModule.TableMotionSpeed();
        //    spdXYH.dMoveSpeed = pathUnitCurrent.全局高速速度;
        //    MainModule.TableMotionSpeed spdXYGlue = new MainModule.TableMotionSpeed();
        //    if (使用单独涂胶速度)
        //    {
        //        spdXYGlue.dMoveSpeed = 单独涂胶速度;
        //    }
        //    else
        //    {
        //        if (空动作路径)
        //        {
        //            spdXYGlue.dMoveSpeed = pathUnitCurrent.全局高速速度;
        //        }
        //        else
        //        {
        //            spdXYGlue.dMoveSpeed = pathUnitCurrent.全局涂胶速度;
        //        }
        //    }




        //    double dFirstPosX, dFirstPosY, dFirstPosZ, dFirstPosU;
        //    GetFirstPointPoint(out dFirstPosX, out dFirstPosY, out dFirstPosZ, out dFirstPosU);

        //    #region 设定速度
        //    bool bIsFirstItem = false;
        //    if (indexId == 0)
        //    {
        //        bIsFirstItem = true;
        //    }
        //    bool bisFinalItem = false;
        //    if (indexId == (pathUnitCurrent.listContinueItems.Count - 1))
        //    {
        //        bisFinalItem = true;
        //    }
        //    bool bContinueWithBeforeItem = false;
        //    if (indexId == 0)
        //    {
        //        bContinueWithBeforeItem = false;
        //    }
        //    else
        //    {
        //        double dBeforeItemPosX, dBeforeItemPosY, dBeforeItemPosZ, dBeforeItemPosU;
        //        pathUnitCurrent.listContinueItems[indexId - 1].GetLastPoint(out dBeforeItemPosX, out dBeforeItemPosY,
        //            out dBeforeItemPosZ, out dBeforeItemPosU);
        //        if (Math.Abs(dBeforeItemPosX - dFirstPosX) < 0.5 && Math.Abs(dBeforeItemPosY - dFirstPosY) < 0.5 && Math.Abs(dBeforeItemPosZ - dFirstPosZ) < 0.5)
        //        {
        //            bContinueWithBeforeItem = true;
        //        }
        //    }
        //    bool bContinueWithAferItem = false;
        //    bool bIsContinueWithAferAndAfterIsOnGlue = false;
        //    if (indexId == (pathUnitCurrent.listContinueItems.Count - 1))
        //    {
        //        bContinueWithAferItem = false;
        //    }
        //    else
        //    {
        //        double dNextItemPosX, dNextItemPosY, dNextItemPosZ, dNextItemPosU;
        //        double dCurrentEndPosX, dCurrentEndPosY, dCurrentEndPosZ, dCurrentEndPosU;
        //        GetLastPoint(out dCurrentEndPosX, out dCurrentEndPosY, out dCurrentEndPosZ, out dCurrentEndPosU);
        //        pathUnitCurrent.listContinueItems[indexId + 1].GetFirstPointPoint(out dNextItemPosX, out dNextItemPosY,
        //            out dNextItemPosZ, out dNextItemPosU);
        //        if (Math.Abs(dCurrentEndPosX - dNextItemPosX) < 0.5 && Math.Abs(dCurrentEndPosY - dNextItemPosY) < 0.5 && Math.Abs(dCurrentEndPosZ - dNextItemPosZ) < 0.5)
        //        {
        //            bContinueWithAferItem = true;
        //            if (pathUnitCurrent.listContinueItems[indexId + 1].空动作路径 == false && pathUnitCurrent.listContinueItems[indexId + 1].Disable == false)
        //            {
        //                bIsContinueWithAferAndAfterIsOnGlue = true;
        //            }
        //        }
        //    }

        //    if (bIsFirstItem && bisFinalItem)//只有一个点
        //    {
        //        spdXYH.dStartSpeed = 0;
        //        spdXYH.dMoveSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dEndSpeed = 0;
        //        spdXYGlue.dStartSpeed = 0;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    if (bIsFirstItem && (!bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程的第一个点和后面有连接
        //    {
        //        spdXYH.dStartSpeed = 0;
        //        spdXYH.dMoveSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dEndSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYGlue.dStartSpeed = 0;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    if (!bIsFirstItem && (!bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程中间点，没有和前面的连接，与后面的连接
        //    {
        //        spdXYH.dStartSpeed = 0;
        //        spdXYH.dEndSpeed = 0;
        //        spdXYGlue.dStartSpeed = 0;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    if (!bIsFirstItem && (bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程中间点，和前面的连接，与后面的连接
        //    {
        //        spdXYH.dStartSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dMoveSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dEndSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYGlue.dStartSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    if (!bIsFirstItem && (bContinueWithBeforeItem) && (!bContinueWithAferItem) && (!bisFinalItem))//流程中间点，和前面的连接，没有与后面的连接
        //    {
        //        spdXYH.dStartSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dMoveSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dEndSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYGlue.dStartSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    if (!bIsFirstItem && (!bContinueWithBeforeItem) && (!bContinueWithAferItem) && (!bisFinalItem))//流程中间点，没有和前面的连接，没有与后面的连接
        //    {
        //        spdXYH.dStartSpeed = 0;
        //        spdXYH.dEndSpeed = 0;
        //        spdXYGlue.dStartSpeed = 0;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    if (!bIsFirstItem && (bContinueWithBeforeItem) && (!bContinueWithAferItem) && (bisFinalItem))//流程最后一个线段，和前面连接
        //    {
        //        spdXYH.dStartSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dMoveSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYH.dEndSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYGlue.dStartSpeed = spdXYGlue.dMoveSpeed;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    if (!bIsFirstItem && (!bContinueWithBeforeItem) && (!bContinueWithAferItem) && (bisFinalItem))//流程最后一个线段，没有和前面连接
        //    {
        //        spdXYH.dStartSpeed = 0;
        //        spdXYH.dEndSpeed = 0;
        //        spdXYGlue.dStartSpeed = 0;
        //        spdXYGlue.dEndSpeed = spdXYGlue.dMoveSpeed;
        //    }
        //    #endregion

        //    double dZHeight = dFirstPosZ;
        //    if (this.bUseZheight)
        //    {
        //        if (pathUnitCurrent.dicZheightItems.ContainsKey(UseZheightName))
        //        {
        //            dZHeight = pathUnitCurrent.dicZheightItems[UseZheightName].MotorZData;
        //        }
        //    }

        //    MainModule.TableDataPosition pos1 = new MainModule.TableDataPosition();
        //    pos1.dXPos = dFirstPosX;
        //    pos1.dYPos = dFirstPosY;
        //    pos1.dZPos = bUseZheight ? dZHeight : dFirstPosZ;
        //    pos1.dUPos = dFirstPosU;
        //    pos1.strLocal = pathUnitCurrent.LocalName;

        //    tableRunner.SetSpd(spdXYH);
        //    if (bContinueWithBeforeItem == false)
        //    {
        //        MainModule.TableDataPosition pos1Up = new MainModule.TableDataPosition(pos1);
        //        pos1Up.dZPos = 0;
        //        tableRunner.PushLineToCure(pos1Up);

        //    }
        //    tableRunner.PushLineToCure(pos1);
        //    if (空动作路径 == false)
        //        tableRunner.PushExtDo(MainModule.IOManager.Output(pathUnitCurrent.GlueOutputName).iChannal, 1);
        //    tableRunner.PushDelay(this.出胶时间);
        //    if (bIsContinueWithAferAndAfterIsOnGlue == false)
        //        tableRunner.PushExtDo(MainModule.IOManager.Output(pathUnitCurrent.GlueOutputName).iChannal, 0);
        //    tableRunner.PushDelay(this.关胶延时);

        //    if (bContinueWithAferItem == false)
        //    {
        //        MainModule.TableDataPosition pos1Up = new MainModule.TableDataPosition(pos1);
        //        pos1Up.dZPos = 0;
        //        tableRunner.PushLineToCure(pos1Up);
        //    }


        //}
        public override void OffSetPos(double dOffSetX, double dOffSetY, double dOffSetZ)
        {
            Pos.X = Pos.X + dOffSetX;
            Pos.Y = Pos.Y + dOffSetY;
            Pos.Z = Pos.Z + dOffSetZ;



        }
        public override void SetZPos(double dSetPosZ)
        {

            Pos.Z = dSetPosZ;




        }
        public override void SetUPos(double dSetPosU)
        {

            Pos.Z = dSetPosU;




        }
        public override void UpdateZheight(double dZHeight)
        {
           
            
                Pos.Z = dZHeight;
           
        }
        public override void GetItemMinMaxXY(out double dMinX, out double dMinY, out double dMaxX, out double dMaxY)
        {
            base.GetItemMinMaxXY(out dMinX, out dMinY, out dMaxX, out dMaxY);

            dMinX = Pos.X;
            dMinY = Pos.Y;
            dMaxX = Pos.X;
            dMaxY = Pos.Y;
        }
        public override void UpdateEndPos(double dNewEndX, double dNewEndY)
        {
            Pos.X = dNewEndX;
            Pos.Y = dNewEndY;
        }
        public override void UpdateStartPos(double dNewStartX, double dNewStartY)
        {
            Pos.X = dNewStartX;
            Pos.Y = dNewStartY;
        }
        public override void PushItem(List<MotionItemBase> motionItems, GluePathGroup gluePathGroup, GluePathUnit gluePathUnit, int indexId, double dOffsetZ)
        {
            TranferPosToCur(gluePathUnit,dOffsetZ);

            SpdData spdXYGlue = new SpdData();
            SpdData spdXYH = new SpdData();
            SpdData spdZH = new SpdData();


            double dFirstPosX, dFirstPosY, dFirstPosZ, dFirstPosU;
            GetFirstPoint(out dFirstPosX, out dFirstPosY, out dFirstPosZ, out dFirstPosU);

            #region 判断胶路类型
            bool bIsFirstItem = false;
            bool bisFinalItem = false;
            bool bContinueWithBeforeItem = false;
            bool bContinueWithAferItem = false;
            bool bIsContinueWithAferAndAfterIsOnGlue = false;
            if (indexId == 0)
            {
                bIsFirstItem = true;
            }
            if (indexId == (gluePathUnit.listContinueItems.Count - 1))
            {
                bisFinalItem = true;
            }
            if (indexId == 0)
            {

            }
            else
            {
                double dBeforeItemPosX, dBeforeItemPosY, dBeforeItemPosZ, dBeforeItemPosU;
                gluePathUnit.listContinueItems[indexId - 1].GetLastPoint(out dBeforeItemPosX, out dBeforeItemPosY,
                    out dBeforeItemPosZ, out dBeforeItemPosU);
                if (Math.Abs(dBeforeItemPosX - dFirstPosX) < 0.5 && Math.Abs(dBeforeItemPosY - dFirstPosY) < 0.5 && Math.Abs(dBeforeItemPosZ - dFirstPosZ) < 0.5)
                {
                    bContinueWithBeforeItem = true;
                }
            }
            if (indexId == (gluePathUnit.listContinueItems.Count - 1))
            {
                bContinueWithAferItem = false;
            }
            else
            {
                double dNextItemPosX, dNextItemPosY, dNextItemPosZ, dNextItemPosU;
                double dCurrentEndPosX, dCurrentEndPosY, dCurrentEndPosZ, dCurrentEndPosU;
                GetLastPoint(out dCurrentEndPosX, out dCurrentEndPosY, out dCurrentEndPosZ, out dCurrentEndPosU);
                gluePathUnit.listContinueItems[indexId + 1].GetFirstPoint(out dNextItemPosX, out dNextItemPosY,
                    out dNextItemPosZ, out dNextItemPosU);
                if (Math.Abs(dCurrentEndPosX - dNextItemPosX) < 0.5 && Math.Abs(dCurrentEndPosY - dNextItemPosY) < 0.5 && Math.Abs(dCurrentEndPosZ - dNextItemPosZ) < 0.5)
                {
                    bContinueWithAferItem = true;
                    if (gluePathUnit.listContinueItems[indexId + 1].空动作路径 == false && gluePathUnit.listContinueItems[indexId + 1].Disable == false)
                    {
                        bIsContinueWithAferAndAfterIsOnGlue = true;
                    }
                }
            }
            #endregion

            #region 速度设定

            if (使用单独涂胶速度)
            {
                spdXYGlue.dMoveSpd = 单独涂胶速度;
            }
            else
            {
                if (空动作路径)
                {
                    spdXYGlue.dMoveSpd = gluePathUnit.全局XY高速速度;
                }
                else
                {
                    spdXYGlue.dMoveSpd = gluePathUnit.全局涂胶速度;
                }
            }
            spdXYH.dStartSpd = gluePathUnit.全局开始速度;
            spdXYH.dMoveSpd = gluePathUnit.全局XY高速速度;
            spdXYH.dEndSpd = gluePathUnit.全局结束速度;
            spdXYH.dAcc = gluePathUnit.全局加速度;
            spdXYH.dDec = gluePathUnit.全局减速度;
            spdZH.dStartSpd = gluePathUnit.全局开始速度;
            spdZH.dMoveSpd = gluePathUnit.全局Z高速速度;
            spdZH.dEndSpd = gluePathUnit.全局结束速度;
            spdZH.dAcc = gluePathUnit.全局加速度;
            spdZH.dDec = gluePathUnit.全局减速度;
            if (bIsFirstItem && bisFinalItem)//只有一个点
            {
                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (bIsFirstItem && (!bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程的第一个点和后面有连接
            {

                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;

            }
            if (!bIsFirstItem && (!bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程中间点，没有和前面的连接，与后面的连接
            {

                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;

            }
            if (!bIsFirstItem && (bContinueWithBeforeItem) && (bContinueWithAferItem) && (!bisFinalItem))//流程中间点，和前面的连接，与后面的连接
            {

                spdXYGlue.dStartSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dEndSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (!bIsFirstItem && (bContinueWithBeforeItem) && (!bContinueWithAferItem) && (!bisFinalItem))//流程中间点，和前面的连接，没有与后面的连接
            {
                spdXYGlue.dStartSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;

            }
            if (!bIsFirstItem && (!bContinueWithBeforeItem) && (!bContinueWithAferItem) && (!bisFinalItem))//流程中间点，没有和前面的连接，没有与后面的连接
            {
                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (!bIsFirstItem && (bContinueWithBeforeItem) && (!bContinueWithAferItem) && (bisFinalItem))//流程最后一个线段，和前面连接
            {
                spdXYGlue.dStartSpd = spdXYGlue.dMoveSpd;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            if (!bIsFirstItem && (!bContinueWithBeforeItem) && (!bContinueWithAferItem) && (bisFinalItem))//流程最后一个线段，没有和前面连接
            {
                spdXYGlue.dStartSpd = gluePathUnit.全局开始速度;
                spdXYGlue.dEndSpd = gluePathUnit.全局结束速度;
                spdXYGlue.dAcc = gluePathUnit.全局加速度;
                spdXYGlue.dDec = gluePathUnit.全局减速度;
            }
            #endregion

            #region 轨迹设定


            if (bContinueWithBeforeItem == false)
            {
                MotionItemLine motionItemLineUp = new MotionItemLine(spdXYH, PosTransfer);
                motionItemLineUp.Point.Z = gluePathUnit.全局安全高度Z;
                motionItems.Add(motionItemLineUp);
                MotionItemLine motionItemLineStart = new MotionItemLine(spdZH, PosTransfer);
                motionItems.Add(motionItemLineStart);

            }

            if (空动作路径 == false)
            {
                MotionItemOutput motionItemOutput = new MotionItemOutput();
                motionItemOutput.On = true;
                motionItems.Add(motionItemOutput);
            }

            if (this.开胶后延时时间 > 0)
            {
                MotionItemDelay motionItemDelay = new MotionItemDelay();
                motionItemDelay.dDelayTime = this.开胶后延时时间;
                motionItems.Add(motionItemDelay);
            }

            

            //MotionItemLine motionItemLine = new MotionItemLine(spdXYGlue, Pos2Transfer);
            //motionItems.Add(motionItemLine);

            if (bIsContinueWithAferAndAfterIsOnGlue == false)
            {
                MotionItemOutput motionItemOutput = new MotionItemOutput();
                motionItemOutput.On = false;
                motionItems.Add(motionItemOutput);
            }
            if (bContinueWithAferItem == false)
            {
                MotionItemLine motionItemLineUp = new MotionItemLine(spdZH, PosTransfer);
                motionItemLineUp.Point.Z = gluePathUnit.全局安全高度Z;
                motionItems.Add(motionItemLineUp);
            }
            #endregion
        }

        private void TranferPosToCur(GluePathUnit gluePathUnit,double dOffsetZ)
        {
            PointData pointDataLocalPos = WhereAtLocal(Pos, gluePathUnit.StandardLocalX, gluePathUnit.StandardLocalY, gluePathUnit.StandardLocalU);
            PosTransfer = TranLocalToMotor(pointDataLocalPos, gluePathUnit.CurrentLocalX, gluePathUnit.CurrentLocalY, gluePathUnit.CurrentLocalU);
            AddToolOffSet(gluePathUnit, PosTransfer);

            PosTransfer.Z = PosTransfer.Z-dOffsetZ;

        }
    }
}
